<template>
  <div class="represent-wrapper">
    <div class="top">
      <div class="title-wrapper">
        <div class="title">代言管理</div>
      </div>
    </div>
    <div class="middle">
      <Input placeholder="请输入用户名/手机号" @search="handleSearch" />
    </div>
    <div class="bottom">
      <table-list :list="list" />
    </div>
    <Paginaton class="pagination" :total="total" :page-size="pageSize" :cur-page="currentPage" @nextPage="handleNextPage" />
  </div>
</template>
<script>
import Input from '@/common/input'
import TableList from './list/tableList'
import Paginaton from '@/common/pagination'
import { getRepresentList } from '@/api/represent'
const ERR_OK = 200
export default {
  components: {
    Input,
    TableList,
    Paginaton
  },
  data() {
    return {
      list: [],
      query: '',
      total: 0,
      currentPage: 1,
      pageSize: 10
    }
  },
  created() {
    this._getRepresentList(this.page)
  },
  methods: {
    handleNextPage(page) {
      this.currentPage = page
      this._getRepresentList(this.currentPage, this.query)
    },
    handleSearch(query) {
      this.query = query
      this.currentPage = 1
      this._getRepresentList(this.currentPage, this.query)
    },
    _getRepresentList(page, keyword) {
      getRepresentList(page, keyword)
        .then(res => {
          if (res.code === ERR_OK) {
            console.log(res)
            this.total = res.data.total
            this.list = res.data.list
          }
        })
        .catch(err => {
          console.log(err)
        })
    }
  }
}
</script>
<style lang="scss" scoped>
@import '@/styles/el-pagination.scss';
.represent-wrapper {
  padding: 0 20px;
  box-sizing: border-box;
  .top {
    width: 100%;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    .title-wrapper {
      display: flex;
      align-content: center;
      .title {
        height: 44px;
        line-height: 44px;
        color: rgba(68, 68, 68, 1);
        font-size: 18px;
        font-family: Roboto;
        font-weight: bold;
        cursor: pointer;
      }
    }
  }
  .bottom{
    margin-top: 20px;
  }
}
</style>
